package com.learnMyBatis.mapper;


import com.alibaba.druid.sql.visitor.functions.Char;
import com.learnMyBatis.entity.Car;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;


import java.util.List;
@Mapper
public interface CarMapper {
    @Select("select * from car")
    public List<Car> list();
    @Delete("delete from car where car_id = #{carId}")
    public void delete(String carId);

    @Options(keyProperty = "carId",useGeneratedKeys = true)//返回主键值
    @Insert("insert into car(car_name,car_model,car_price,car_color,body_style) values(#{carName},#{carModel},#{carPrice}," +
            "#{carColor},#{bodyStyle})")
    public void insert(Car car);

//    @Update("update car set car_name = #{carName} where car_id = #{carId}")
    public void update(Car car);

    @Select("select * from car where car_id=#{carId}")
    public Car selectById(String carId);
//    @Select("select * from car where car_name like concat('%',#{carName},'%') and car_color = #{carColor}")
    public List<Car> listbyCon(String carName,String carColor);


//  上述代码获取不到car的数据。是因为数据库字段和属性字段不一致有两种方法
//1.取别名
//    @Select("select car_id carId,car_name carName,car_model carModel,car_price carPrice, " +
//            "car_color carColor,body_style bodyStyle  from car where car_id=#{carId}")
//    public Car selectById(String carId);
//    2.用注解

//    @Results({
//            @Result(column = "",property = ""),
//            @Result(column = "",property = ""),
//            @Result(column = "",property = ""),
//            @Result(column = "",property = ""),
//    })
//    @Select("select * from car where car_id=#{carId}")
//    public Car selectById(String carId);
//3.开启mybatis自动转换开关


//    批量删除
    public void deleteByIds(List<Character> list);

}
